/* @formatter:off
 * Copyright (c) 2011 Lucas <lucas03093@gmail.com>
 * 
 * 
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
/* @formatter:on */

package nu.korkad.daytracker.alertdialog;

import nu.korkad.daytracker.R;
import nu.korkad.daytracker.info.Dates;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.text.SpannableString;
import android.text.util.Linkify;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

public class Archive
{
    /**
     * Creates a dialog (popup).
     * 
     * @param context
     * @param buttonText
     *            String
     * @param changelog
     *            String
     * @param newVersion
     *            String
     * @return AlertDialog
     */
    public static Builder create(final Context context, String companyName, String text, long checkin, long checkout, final long id,
            final int unread)
    {
        // Get layout
        View layout = LayoutInflater.from(context).inflate(R.layout.activity_archive_alertdialog, null);
        
        // Set text and make links clickable
        final TextView message = (TextView) layout.findViewById(R.id.layout_archive_alertdialog_textview);
        final SpannableString s = new SpannableString(context.getString(R.string.dialog_archive_text_id) + " " + id + "\n"
                + context.getString(R.string.dialog_archive_text_company) + " " + companyName + "\n"
                + context.getString(R.string.dialog_archive_text_checkin) + " " + Dates.getArchiveDate(checkin, context) + "\n"
                + context.getString(R.string.dialog_archive_text_checkout) + " " + Dates.getArchiveDate(checkout, context) + "\n"
                + context.getString(R.string.dialog_archive_text_duration) + " "
                + Dates.getDuration(checkin * 1000, checkout * 1000, context) + "\n\n"
                + context.getString(R.string.dialog_archive_text_report) + "\n" + text);
        
        // Set some padding
        message.setPadding(5, 5, 5, 5);
        
        // Set the dialog text
        message.setText(s);
        
        // Turn web addresses to links
        Linkify.addLinks(message, Linkify.WEB_URLS);
        
        return new AlertDialog.Builder(context).setTitle(context.getString(R.string.dialog_archive_text_title)).setCancelable(true)
                .setPositiveButton(context.getString(R.string.dialog_archive_button_ok), null).setView(layout);
    }
}
